package com.software.project.service;

import com.software.project.entity.Suit;
import com.software.project.repository.SuitRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

@Service
@Slf4j
public class SuitServiceImpl implements SuitService{

    @Autowired
    private SuitRepository suitRepository;

    @Override
    public List<Suit> findUnlockingSuit(int intelligence, int power) {
        log.debug("intelligence: {}, power: {}", intelligence, power);
        List<Suit> suitList = suitRepository.findBySuitRequireIntelligenceLessThanEqualAndSuitRequirePowerLessThanEqual(intelligence, power);
        log.debug("suitList: {}", suitList);
        return suitList;
    }

    @Override
    public List<Suit> findLockedSuit(int intelligence, int power) {
        log.debug("intelligence: {}, power: {}", intelligence, power);
        List<Suit> suitList = suitRepository.findBySuitRequireIntelligenceGreaterThanOrSuitRequirePowerGreaterThan(intelligence, power);
        log.debug("suitList: {}", suitList);
        return suitList;
    }

    @Override
    public Suit findSuitBySuitId(Integer suitId) {
        log.debug("suitId: {}", suitId);
        Optional<Suit> optional = suitRepository.findById(suitId);
        if (optional.isPresent()) {
            log.debug("suit: {}", optional.get());
            return optional.get();
        } else {
            log.warn("suit: {}", "null");
            return null;
        }
    }
    @Override
    public Suit findSuitBySuitImage(String suitImage) {
        log.debug("suitImage: {}", suitImage);
        Optional<Suit> bySuitSrc = suitRepository.findBySuitSrc(suitImage);
        if (bySuitSrc.isPresent()) {
            log.debug("suit: {}", bySuitSrc.get());
            return bySuitSrc.get();
        } else {
            log.debug("suit: {}", bySuitSrc.get());
            return null;
        }
    }
}
